﻿using System.Linq;
using HtmlAgilityPack;
using NUnit.Framework;
using Fizzler.Systems.HtmlAgilityPack;

namespace HtmlDeploy.Test
{
    [TestFixture]
    public class NodeFixture
    {
        [Test]
        public void RawText()
        {
            var html = new HtmlDocument();
            html.LoadHtml(
@"<html>
      <head></head>
      <script>
           $(function({alert('yes');})
      </script>
      <body>
        <div>
          <p class='content'>Fizzler</p>
          <p>CSS Selector Engine</p></div>
      </body>
  </html>");

            var scripts = html.DocumentNode.QuerySelectorAll("script");
            var script = scripts.Single();

            Assert.That(script.InnerText.Trim(), Is.EqualTo(@"$(function({alert('yes');})"));
            Assert.That(script.GetAttributeValue("src", ""), Is.EqualTo(""));
        }

        [Test]
        public void GetAttr()
        {
            var html = new HtmlDocument();
            html.LoadHtml(
@"<html>
      <head></head>
      <script src='www.google.com'></script>
      <body>
        <div>
          <p class='content'>Fizzler</p>
          <p>CSS Selector Engine</p></div>
      </body>
  </html>");

            var scripts = html.DocumentNode.QuerySelectorAll("script");
            var script = scripts.Single();

            Assert.That(script.GetAttributeValue("src",""), Is.EqualTo("www.google.com"));
            Assert.That(script.InnerText, Is.EqualTo(""));
        }
    }
}
